//快乐数
https://leetcode.cn/problems/happy-number/submissions/589259602/

class Solution {
public:
    void change(int& n) {
        string str = std::to_string(n);
        int sum = 0;
        for (auto& e : str) {
            sum += pow(e - '0', 2);
        }
        n = sum;
    }

    bool isHappy(int n) {
        int slow = n;
        int fast = n;
        change(fast);
            change(fast);
            change(slow);
        while (slow != 1 && fast != 1) {
            change(fast);
            change(fast);
            change(slow);
            cout << fast << " " << slow << endl;
            if (fast == slow) {
                return false;
            }
        }
        return true;
    }
};